using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace Hawkeye
{

  public class HawkService : Hawk.IService
  {
    public interface IService
    {
      string ProduceFrequenceReport(Dictionary<string, int> freqTable);
    }
    IService service;
    string upperLetter = "A-Z";
    string idLetter = "A-Za-z0-9";
    public HawkService(IService service)
    {
      this.service = service;
    }
    public List<string> FindClassNames(string text)
    {
      MatchCollection coll = Regex.Matches(text, "class ([" + upperLetter + "][" + idLetter + "]*)");
      Dictionary<string, bool> dict = new Dictionary<string, bool>();
      foreach (Match m in coll)
        dict[m.Groups[1].Value] = true;
      List<string> result = new List<string>(dict.Keys);
      return result;
    }

    public int CountFrequency(string text, string className)
    {
      MatchCollection coll = Regex.Matches(text, "\\s" + className + "[^" + idLetter + "]");
      return coll.Count;
    }

    public string ProduceFrequencyTable(Dictionary<string, int> freqTable)
    {
      return service.ProduceFrequenceReport(freqTable);
    }
  }
}
